<template>
  <div class='wrapper'>
    <div class='content-body'>
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import bus from '@/utils/bus';

export default {
  data() {
    return {
      itemList: [
        // 水平一级菜单栏的菜单
        { path: '/twodgraph', title: '2D图谱' },
        { path: '/threedgraph', title: '3D图谱' }
      ],
      globalTheme: true
    };
  },
  computed: {
    username() {
      return localStorage.getItem('ms_username') || '';
    },
    toIndex() {
      // 根据路径绑定到对应的一级菜单，防止页面刷新重新跳回第一个
      return '/' + this.$route.path.split('/')[1];
    }
  },
  created() {
    this.globalTheme = JSON.parse(localStorage.getItem('global_theme'));
    bus.$emit('global_theme', this.globalTheme); // 将 globalTheme 的值传给父组件
  },
  methods: {
    handleSelect(path) {
      // 切换菜单栏
      this.$router.push({
        path: path
      });
    },
    handleCommand(command) {
      // 用户名下拉菜单选择事件
      if (command == 'loginout') {
        localStorage.removeItem('ms_username');
        this.$router.push({
          path: '/Login'
        });
      }
    },
    handleChangeStyle() {
      // 切换主题
      this.globalTheme = !this.globalTheme;
      localStorage.setItem('global_theme', this.globalTheme); // 本地存储选择的 globalTheme
      bus.$emit('global_theme', this.globalTheme); // 将 globalTheme 的值传给父组件
    }
  }
};
</script>

<style scoped>
.wrapper {
  width: 100%;
  height: 100%;
  background: #f0f0f0;
}

.header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 60px;
  font-size: 22px;
}

.header .logo {
  float: left;
  margin-left: 60px;
  margin-top: 17.5px;
  height: 29px;
  width: 160px;
  vertical-align: middle;
}

/* --------------- 用户头像区域的样式 ---------------- */
.header-right {
  float: right;
  padding-right: 50px;
}

.header-user-con {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 70px;
}

.user-avator {
  margin-left: 20px;
}

.user-avator img {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.user-name {
  margin-left: 10px;
}

.el-dropdown-link {
  cursor: pointer;
}

.el-dropdown-menu__item {
  text-align: center;
}

/* --------------- 水平一级菜单栏的样式--------------------- */
.el-menu.el-menu--horizontal {
  border-bottom: none !important;
  float: left;
  margin-left: 50px;
  background: transparent;
}

.el-menu--horizontal > .el-menu-item.is-active {
  /* border-bottom: 2px solid #3989fa;
color: #3989fa; */
  font-weight: bold;
}

.el-menu--horizontal > .el-menu-item {
  font-size: 16px;
  margin: 0 15px;
}

.content-body {
  height: 100%;
}
</style>
